#ifndef SDFSPRAYALGORITHM_H
#define SDFSPRAYALGORITHM_H

#include <BulletLibDefine.h>
#include <SDF.h>
#include <osg/Vec3>
#include <vector>
#include <osg/Geode>
#include <osg/MatrixTransform>
#include <string>
class BULLET_EDITOR_DLL SDFSprayAlgorithm
{
public:
    static SDFSprayAlgorithm *instance();
    ~SDFSprayAlgorithm();

    //gateway
    void generatePoints(osg::ref_ptr<SDF> sdfPtr);

    void writePointsToFile(std::string fileName);

    //get function
    std::vector<osg::Vec3> getPoints();
    std::vector<osg::Vec3> getNormals();
    osg::ref_ptr<osg::Geode> getPointsGeode();
    osg::ref_ptr<osg::MatrixTransform> getPointsMT();

    //
    void repairTrajectory(std::vector<osg::Vec3>& points);
    void repairTrajectory2(std::vector<osg::Vec3>& points);
protected:
    void updatePointsGeode();
    int findNearestPoint( int pointIndex, std::vector<osg::Vec3>& points);
private:
    SDFSprayAlgorithm();
    static SDFSprayAlgorithm* _instance;

    osg::ref_ptr<SDF> m_currentSDF;
    double m_radius;
    std::vector<osg::Vec3> m_points;
    std::vector<osg::Vec3> m_indexes;
    std::vector<osg::Vec3> m_normals;
    osg::ref_ptr<osg::Geode> m_pointsGeode;
    osg::ref_ptr<osg::MatrixTransform> m_pointsMT;
};

#endif // SDFSPRAYALGORITHM_H
